package com.syyo.gulimall.order.web;

import com.syyo.gulimall.order.config.rabbit.MyMQConfig;
import com.syyo.gulimall.order.domain.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @ author: wang
 * @ date: 2021/4/26 11:00
 * @ Description:
 */
@Controller
public class HelloController {

    @Autowired
    RabbitTemplate rabbitTemplate;// 管理队列对象

    @GetMapping("/{page}.html")
    public String ListPage(@PathVariable("page") String page) {
        return page;
    }

    @ResponseBody
    @GetMapping("/test/createOrder")
    public String createOrder() {

        OrderEntity entity = new OrderEntity();

        entity.setOrderSn(UUID.randomUUID().toString());
        entity.setCreateTime(new Date());

        rabbitTemplate.convertAndSend(MyMQConfig.ORDER_EXCHANGE, MyMQConfig.ORDER_CREATE_ORDER, entity);

        return "ok";

    }
}
